package com.base.cn.platform.os.service.classes.topic.share;

import com.base.cn.platform.os.common.mybatis.BaseBiz;
import com.base.cn.platform.os.common.utils.DataUtil;
import com.base.cn.platform.os.dao.classes.topic.share.ClassesTopicShareRecordDao;
import com.base.cn.platform.os.entity.classes.topic.ClassesTopic;
import com.base.cn.platform.os.entity.classes.topic.share.ClassesTopicShareRecord;
import com.base.cn.platform.os.service.classes.topic.ClassesTopicBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 班级话题分享记录Biz
 *
 * @author zsw
 * @since 2018/7/30
 */
@Service
public class ClassesTopicShareRecordBiz extends BaseBiz<ClassesTopicShareRecord,ClassesTopicShareRecordDao> {

    @Autowired
    private ClassesTopicBiz classesTopicBiz;

    /**
     * 添加分享记录
     *
     * @param topicId 分享的话题id
     * @param userId  分享的用户id
     */
    public void saveShareRecord(BigDecimal topicId, BigDecimal userId) {
        if (!DataUtil.idIsNotNull(topicId) || !DataUtil.idIsNotNull(userId)) {
            return;
        }
        ClassesTopicShareRecord record = new ClassesTopicShareRecord();
        record.setTopicId(topicId);
        record.setUserId(userId);
        ClassesTopic topic = classesTopicBiz.findById(topicId);
        classesTopicBiz.updateClassesTopicStatistics(topic,ClassesTopicBiz.SHARE_NUM,1);
        this.save(record);
    }
}
